<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Event
 *
 * @property int $id
 * @property string $event_name
 * @property int $event_id
 * @property string $category
 * @property string|null $content
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Event newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Event newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Event query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Event whereContent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Event whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Event whereEventId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Event whereEventName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Event whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Event whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Event extends Model
{
    const PRODUCT_CREATE = "PRODUCT_CREATE";
    const PRODUCT_UPDATE = "PRODUCT_UPDATE";
    const PRODUCT_DEL = "PRODUCT_DEL";

    const BRAND_CREATE = "BRAND_CREATE";
    const BRAND_DEL = "BRAND_DEL";

    public $table = "event";

    protected $guarded = [];

    /**
     * @param $event_id
     * @param $event_name
     * @param $content
     * @return Event|Model
     */
    public static function addEvent($event_id, $event_name, $content)
    {
        if (!is_string($content)) {
            $content = json_encode($content);
        }

        return Event::create([
            'event_id' => $event_id,
            'event_name' => $event_name,
            'content' => $content,
            'category' => 'APPLICATION_WEB'
        ]);
    }
}
